#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include <time.h>
#include <string.h>

void do_ls(char *dirName,char res[]);   
int do_stat(char *fileName,int count);

int count;
char* res [100];


int main(int argc,char** argv){
    int count;
    if(argc>1&&argv[1][1]=='a'){
    do_ls( "." ,res);}
    else{
    do_ls( "./" ,res);
    }

    printf("\n");	
    return 0;
}

void do_ls(char *dirName,char res[]){
    DIR *dir;
    struct dirent *dirent_p;
    if((dir = opendir(dirName)) == NULL ){
     fprintf(stderr,"cannot open %s.n", dirName);
     do_stat(dirName,count);
    }else{
      while((dirent_p = readdir(dir)) != NULL){
      count++;
      do_stat(dirent_p->d_name,count);
        }
        closedir(dir);
    
    for(int i=1;i<=count;i++){
	    //printf("8888");
    
    printf("%s  " ,res[i]);
   }
}
}

int do_stat(char *fileName,int count){
   char str[100]={0};
   char* res[100];
   struct stat info;
   if(stat(fileName, &info) == -1){
        perror(fileName);
    }else{
      //show_info(fileName, &info);
      //strcpy(str,fileName);
      res [count] = strcpy(str,fileName);
}
return count;
}


